<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib   uri="http://java.sun.com/jsp/jstl/core"   prefix="c"%>
<html>
<head>
<meta charset="utf-8">
<title>购物车</title>
<link rel="stylesheet" href="css/showcart.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script src="js/imgs.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>

<script>
    window.onload=function footer_img_non(){
      document.getElementById("footer_img").style.display="none";
    }
  </script>
</head>
<body  >
	<div class="con">
		<div class="head">
			<a href="index.jsp"> <img src="img/logo_login.png" alt="" />
			</a>
		</div>
		<div class="shop_box">
			<div class="head_text_box">
				<span id="head_text"> 我的购物车 </span>
			</div>

			<div class="shop_title">
				<div id="st1">商品</div>
				<div id="st2">规格</div>
				<div id="st3">单价</div>
				<div id="st4">数量</div>
				<div id="st5">小计</div>
				<div id="st6">操作</div>
			</div>
			<c:forEach items="${cartpovos}"  var="povo">
			<div class="shop">
			
				
						<div class="s1">
							<div class="s1_img">
								<a href="/fruits/fruit/SearchFruitByFidServlet?fid=${povo.fruit.fid}"><img
									src="img/fruits/${povo.fruit.fid}/(1).jpg" /></a>
							</div>
							<div class="s1_text">
								<a href="/fruits/fruit/SearchFruitByFidServlet?fid=${povo.fruit.fid}">${povo.fruit.fname}</a>
							</div>
						</div>
		
						<div class="s2">${povo.fruit.fnorm }</div>
		
						<div class="s3">
							￥<span id="${povo.cart.cid}up3">${povo.fruit.fprice}</span>
						</div>
		
						<div class="s4">
							<div class="Unum">
								<span id="${povo.cart.cid}numl" class="numl" >-</span>
								<span id="${povo.cart.cid}num3">${povo.cart.ccount}</span>
								<span id="${povo.cart.cid}numr" class="numr" >+</span>
							</div>
						</div>
						<div class="s5">
							￥<span id="${povo.cart.cid}sum3" class="fsum">${povo.subtotal}</span>
						</div>
		
						<div class="s6">
							<a href="/fruits/cart/RemoveCartByCidServlet?cid=${povo.cart.cid}">删除</a>
						</div>
					
					
			</div>
			</c:forEach>

			<div class="shop_footer">&nbsp;</div>
		</div>

		<div class="sum_mon">
			<div class="money">
				商品总金额：<span id="money"></span>
			</div>
			<br /> <input type="button" name="" id="addmon" value="订单结算" />
		</div>
	</div>
	<jsp:include page="footer/footer.jsp"></jsp:include>
	<script type="text/javascript">
		$(function(){
			total();
			
			
			
			$(".numl").click(function(){
				var  cid =  $(this).attr("id").substr(0,32);
				$.ajax({
					cache: false,
					async: false,
					dataType: "json",
					type: "post",
					data: {"key":"jian","cid":cid},
					url: "/fruits/cart/ChangeCartByCidServlet",
					success: function(){
						$("#"+cid+"num3").text(parseInt($("#"+cid+"num3").text())-1);
						var  price =  parseFloat($("#"+cid+"up3").text());
						var  count  =   parseInt($("#"+cid+"num3").text());
						$("#"+cid+"sum3").text((price*count).toFixed(2));
						total();
					}	
				});
				if(parseInt($("#"+cid+"num3").text())<1){
					location.href= "/fruits/cart/RemoveCartByCidServlet?cid="+cid;
				}	
				total();
			});
			///jia		
			$(".numr").click(function(){
				var  cid =  $(this).attr("id").substr(0,32);
				$.ajax({
					cache: false,
					async: false,
					dataType: "json",
					type: "post",
					data: {"key":"jia","cid":cid},
					url: "/fruits/cart/ChangeCartByCidServlet",
					success: function(){
						$("#"+cid+"num3").text(parseInt($("#"+cid+"num3").text())+1);
						
						var  price =  parseFloat($("#"+cid+"up3").text());
						var  count  =   parseInt($("#"+cid+"num3").text());
						
						$("#"+cid+"sum3").text((price*count).toFixed(2));
						total();
					}				
				});
			});		
		});
		
		function  total(){
			var  total   =  0;
			//alert(total);
			$(".fsum").each(function(){
				
				total  +=parseFloat($(this).text());
				
				
			});
			$("#money").text("￥"+total.toFixed(2).toString());
			
		}
	</script>
</body>
</html>
